#pragma once

#include <string>
#include <utility>
#include <vector>

#include "abstract_expression.h"
#include "catalog.hpp"
#include "logical_type.hpp"

namespace DaseX {

enum class ComparisonType : uint8_t {
  Equal,
  NotEqual,
  LessThan,
  LessThanOrEqual,
  GreaterThan,
  GreaterThanOrEqual
};

class ComparisonExpression : public AbstractExpression {
public:
  ComparisonExpression(AbstractExpressionRef left, AbstractExpressionRef right,
                       ComparisonType comp_type)
      : AbstractExpression({std::move(left), std::move(right)},
                           LogicalType::BOOL),
        comp_type_{comp_type} {}

  auto Evaluate(const arrow::RecordBatch *tuple,
                const arrow::Schema &schema) const -> int override {
    int lhs = GetChildAt(0)->Evaluate(tuple, schema);
    int rhs = GetChildAt(1)->Evaluate(tuple, schema);
    // 目前写死 ==
    // TODO 类型系统建设后，是否还要 Evaluate 函数？ 数的传递 在 plan 部分还是
    // operator
    return lhs == rhs;
  }

  auto EvaluateJoin(const arrow::RecordBatch *left_tuple,
                    const arrow::Schema &left_schema,
                    const arrow::RecordBatch *right_tuple,
                    const arrow::Schema &right_schema) const -> int override {
    int lhs = GetChildAt(0)->EvaluateJoin(left_tuple, left_schema, right_tuple,
                                          right_schema);
    int rhs = GetChildAt(1)->EvaluateJoin(left_tuple, left_schema, right_tuple,
                                          right_schema);
    return lhs == rhs;
  }

  EXPR_CLONE_WITH_CHILDREN(ComparisonExpression);

  ComparisonType comp_type_;
};
} // namespace DaseX
